{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "1412827c-808e-4e57-9079-4125d38457c2",
   "metadata": {},
   "source": [
    "# GHZ State Preparation"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cec94541-0b62-41a5-bec7-90a0956c8ffa",
   "metadata": {},
   "source": [
    "Use the `prepare_ghz_state` function to create a Greenberger-Horne-Zeilinger (GHZ) state.\n",
    "i.e., a balanced superposition of all ones and all zeros, on an arbitrary number of qubits."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "688a9aaa-3c00-4f4f-b302-61a85c6932e6",
   "metadata": {},
   "source": [
    "## Syntax"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ef00713b-ed2c-40b4-a7ca-e5db21d7153c",
   "metadata": {},
   "source": [
    "Function: `prepare_ghz_state`\n",
    "\n",
    "Arguments:\n",
    "\n",
    "- `size: CInt`\n",
    "- `q: Output[QArray[QBit]]`"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2652bf37-f689-4118-8626-49712264ba38",
   "metadata": {},
   "source": [
    "## Example\n",
    "`prepare_ghz_state` on 5 qubits\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "5bc1f2fb-5344-4602-82ee-76d1d642119f",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-05-07T13:26:04.635676Z",
     "iopub.status.busy": "2024-05-07T13:26:04.635221Z",
     "iopub.status.idle": "2024-05-07T13:26:07.412964Z",
     "shell.execute_reply": "2024-05-07T13:26:07.412298Z"
    }
   },
   "outputs": [],
   "source": [
    "from classiq import Output, QArray, QBit, create_model, prepare_ghz_state, qfunc\n",
    "\n",
    "\n",
    "@qfunc\n",
    "def main(x: Output[QArray[QBit]]):\n",
    "    prepare_ghz_state(5, x)\n",
    "\n",
    "\n",
    "qmod = create_model(main)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ffe08c9b-ca87-49d9-bac6-b0a59157e798",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-05-07T13:26:07.417719Z",
     "iopub.status.busy": "2024-05-07T13:26:07.416426Z",
     "iopub.status.idle": "2024-05-07T13:26:09.869314Z",
     "shell.execute_reply": "2024-05-07T13:26:09.868545Z"
    }
   },
   "outputs": [],
   "source": [
    "from classiq import synthesize, write_qmod\n",
    "\n",
    "write_qmod(qmod, \"prepare_ghz_state\")\n",
    "qprog = synthesize(qmod)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
